@extends('layouts.app')

@section('content')
<div class="content order content_analysis">
	<div class="button">
		<span class="business">
			@if(count($business) == 1)
			<label>所有商家</label><i></i>
			<ul>
				<li data-activity="{{ json_encode($business[0]->activitys->load(['types'=>function($query) use ($business){
					return $query->where('business_id',$business[0]->id);
				}])->toArray()) }}" business="{{$business[0]->id}}">{{$business[0]->name}}</li>
			</ul>
			@else
			<label>所有商家</label><i></i>
			<ul>
				@foreach($business as $item)
				<li data-activity="{{ json_encode($item->activitys->load(['types'=>function($query) use ($item){
					return $query->where('business_id',$item->id);
				}])->toArray()) }}">{{$item->name}}</li>
				@endforeach
			</ul>
			@endif
		</span>
		<span class="activity">
			<label>所有活动</label><i></i>
			<ul>
			</ul>
		</span>
		<span class="channel">
			<label>所有渠道</label><i></i>
			<ul>
			</ul>
		</span>
		<button class="search_analysis_num" onclick="searchNum(this)">搜索</button>
	</div>
	<div class="title">
		主要数据统计
		<span><div>
			<p><span>导入订单数据条数</span><label>即导入后台的订单数据条数；</label></p>
			<p><span>短信发送条数</span><label>根据导入的订单数据，后台会发送活动短信，每条订单数据只可发送一条；</label></p>
			<p><span>短信点击次数</span><label>活动短信的点击次数，同一用户多次点击计为多次；</label></p>
			<p><span>短信点击人数</span><label>首次点击活动短信的用户数，同一用户多次点击计为一次；</label></p>
			<p><span>分享次数</span><label>用户在六度APP内分享抽奖链接的次数，同一用户多次分享计为多次；</label></p>
			<p><span>分享人数</span><label>首次在六度APP内分享抽奖链接的用户数，同一用户多次分享计为一次；</label></p>
			<p><span>参与人数</span><label>点击微信链接进入抽奖页面，点击抽奖的人数，一位用户最多可抽奖一次；</label></p>
			<p><span>中奖人数</span><label>点击微信链接进入抽奖页面，点击抽奖后，抽中奖品的人数。</label></p>
		</div></span>
	</div>
	<div id="nums">
	</div>
	<p class="interval"></p>
	<div class="data_chart">
		<div class="button">
			<span class="business">
				@if(count($business) == 1)
				<label>所有商家</label><i></i>
				<ul>
					<li data-activity="{{ json_encode($business[0]->activitys->load(['types'=>function($query) use ($business){
						return $query->where('business_id',$business[0]->id);
					}])->toArray()) }}" business="{{$business[0]->id}}">{{$business[0]->name}}</li>
				</ul>
				@else
				<label>所有商家</label><i></i>
				<ul>
					@foreach($business as $item)
					<li data-activity="{{ json_encode($item->activitys->load(['types'=>function($query) use ($item){
						return $query->where('business_id',$item->id);
					}])->toArray()) }}">{{$item->name}}</li>
					@endforeach
				</ul>
				@endif
			</span>
			<span class="activity">
				<label>所有活动</label><i></i>
				<ul>
				</ul>
			</span>
			<span class="channel">
				<label>所有渠道</label><i></i>
				<ul>
				</ul>
			</span>
			<button class="search_analysis_chart" onclick="searchChart(this)">搜索</button>
		</div>
		<div class="choose_title"><span>
			<label data-type="smsSend" for="">短信发送条数</label><i></i>
			<ul>
				<li data-type="smsSend">短信发送条数</li>
				<li data-type="smsClick">短信点击条数</li>
				<li data-type="smsUser">短信点击人数</li>
				<li data-type="shareNum">分享次数</li>
				<li data-type="shareUser">分享人数</li>
				<li data-type="joinNum">参与人数</li>
				<li data-type="joinSuccess">中奖人数</li>
			</ul>
		</span>
		<label for="">（活动在短信发送后开始，并统计各项数据及趋势）</label>
	</div>
	<div class="choose_date"><span>
		<label data-time="7" for="">活动开始7天内</label><i></i>
		<ul>
			<li data-time="7">活动开始7天内</li>
			<li data-time="all">整个活动周期</li>
		</ul>
	</span><label for="">粒度：<span>天</span></label></div>
	<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
	<div id="main" style="width: 960px;height:400px;"></div>
	<div style="display: none;" id="chart"></div>
</div>
</div>
@endsection

@section('scripts')
<script src='{{ asset("js/echarts.simple.min.js") }}'></script>
<script type="text/javascript">
//获取次数统计
getNums();
//获取图表
getChart();

function getNums(param) {
    param = typeof param !== 'undefined' ? $.param(param) : '';
	$.ajax({
		type: 'get',
		url: '/analysicNum?' + param,
		dataType: 'html',
		success: function(data){
			$('#nums').html(data)
		}
	});
}

function getChart(param) {
    param = typeof param !== 'undefined' ? $.param(param) : '';
	$.ajax({
		type: 'get',
		url: '/analysicChart?' + param,
		dataType: 'html',
		success: function(data){
			$('#chart').html(data)
		}
	});
}

function searchNum(_this){
	var business=$(_this).parents('.button').find('.business').attr('business');
	var activity=$(_this).parents('.button').find('.activity').attr('activity');
	var map=$(_this).parents('.button').find('.channel').attr('map');

	var params = new Object();

	params.business = business ? business: '';
	params.activity = activity ? activity: '';
	params.map = map ? map: '';

	getNums(params);
}

function searchChart(_this) {
	var business=$(_this).parents('.button').find('.business').attr('business');
	var activity=$(_this).parents('.button').find('.activity').attr('activity');
	var map=$(_this).parents('.button').find('.channel').attr('map');
	var type=$('.data_chart>.choose_title>span>label').attr('data-type');
	var time=$('.data_chart>.choose_date>span>label').attr('data-time');

	var params = new Object();
	if(business==undefined){
		box.tipHover({ status: 0, msg: "请选择商家" });
		return false;
	}
	if (activity==undefined) {
		box.tipHover({ status: 0, msg: "请选择活动" });
		return false;
	}
	params.business = business ? business: '';
	params.activity = activity ? activity: '';
	params.map = map ? map: '';
	params.type = type ? type: '';
	params.time = time ? time: '';

	getChart(params);
}
</script>
@endsection
